home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / futils / futils~1 / src / misc1s.zoo / misc1 / combine / combine.h next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  16.0 KB  |  547 lines

  1. #ifdef ALLOC
  2. #   define EXTERN
  3. #   define INIT( _x ) = _x
  4. #else
  5. #   define EXTERN extern
  6. #   define INIT( _x )
  7. #endif
  8.  
  9. /* 
  10.  * Some OS dependent stuff
  11.  */
  12. #define rfa_type long
  13.  
  14. #define SZ$_FILE_NAME 256
  15. #ifdef VOS    /* 24-bit word */
  16. #define HI7       077400000    /* Hi 7 bits of a word */
  17. #else        /* 32-bit word */
  18. #define HI7       0xFE000000    /* Hi 7 bits of a word */
  19. #endif
  20.  
  21. /*
  22.  * Cache Entry:
  23.  *
  24.  * This structure describes a single entry in the cache of lines.
  25.  * The cache is organized as a linked list of cache entries.
  26.  * The entries at the front of the list are the most recently accessed.
  27.  * The variables 'cache_head_ptr' and 'cache_tail_ptr' point to the
  28.  * head and the tail of the cache.
  29.  */
  30.  
  31. struct cache_entry_struct;
  32. typedef struct cache_entry_struct       cache_entry_type;
  33.  
  34. struct cache_entry_struct {
  35.  
  36.     cache_entry_type * cache_next_ptr;/* Link to the next cache entry */
  37.  
  38.     cache_entry_type * cache_prev_ptr;/* Link to the prev cache entry */
  39.  
  40.     int     hash_code;    /* The hash code for the line. A a value of
  41.                    HASH_FREE_ENTRY indicates this is a free
  42.                    cache entry. */
  43.  
  44.     int     record_length;    /* Length of the record */
  45.  
  46.     char    *recordp;    /* Actual record contents. */
  47.  
  48.     int    record_alen;    /* Allocated length of recordp buffer */
  49.  
  50. };
  51.  
  52. #define CACHE_ENTRIES 500    /* Total number of cache entries */
  53. EXTERN cache_entry_type * cache_head_ptr;/* Head of the cache linked list. */
  54. EXTERN cache_entry_type * cache_tail_ptr;/* Head of the cache linked list. */
  55.  
  56.  
  57. #define LINE_LENGTH 135        /* Default line length */
  58. #define PAGE_LENGTH  66        /* Default page length */
  59. #define HEAD_LENGTH   9     /* # lines of output page headings */
  60.  
  61. /* Maximum number of characters in a record */
  62. /*
  63.  * record_type:
  64.  *
  65.  * This structure describes a single record in a file.
  66.  * The 'file_type' structure points to an array of these entries.
  67.  */
  68.  
  69. struct record_struct;
  70. typedef struct record_struct    record_type;
  71.  
  72. struct record_struct {
  73.  
  74.     rfa_type rfa;        /* The record's file address. This is an
  75.                    operating system dependent value which is a
  76.                    token which can be used to seek to the
  77.                    specified record. */
  78.  
  79. /*
  80.  * The 'value' field describes the relationship between this record and
  81.  * another record in another file. Valid values are:
  82.  *
  83.  * Negative:        hash code for the record (See 'is_hash_code' macro).
  84.  *                  A hash code is an index into the symbol table.
  85.  * 0 or Positive:   index into record array of other file.
  86.  *
  87.  * The defines below are used to describes whether the 'value[0]' or
  88.  * 'value[1]' field is used to describe a relationship between files.
  89.  */
  90.  
  91. #define MAX_VALUE_SUB 2
  92.  
  93.     int     value[MAX_VALUE_SUB];
  94.                 /* Describes the relationship between this
  95.                    record and another record in another file.
  96.                 */
  97.  
  98.  
  99. #define OLD_TO_NEW1         0    /* Old file: index into new1  */
  100. #define OLD_TO_NEW2         1    /* Old file: index into new2  */
  101. #define NEW1_TO_OLD         0    /* new1 file: index into old  */
  102. #define NEW1_TO_NEW2        1    /* new1 file: index into new2 */
  103. #define NEW2_TO_OLD         0    /* new2 file: index into old  */
  104. #define NEW2_TO_NEW1        1    /* new2 file: index into new1 */
  105.  
  106. };
  107.  
  108. /*
  109.  * Record index values:
  110.  *
  111.  * Record indexes include a special record at the beginning of the file
  112.  * and a special record at the end of the file. These definitions describe
  113.  * that phenomena.
  114.  */
  115.  
  116. #define BEGIN_INDEX 0        /* Index of the dummy begin record */
  117. #define DUMMY_RECORD_COUNT 2    /* Number of dummy records */
  118.  
  119. /*
  120.  * File Description:
  121.  *
  122.  * This structure describes a single input file.
  123.  * A structure of this type occurs for the 'old' file, 'new1' file,
  124.  * and 'new2' file.
  125.  */
  126.  
  127. struct file_struct;
  128. typedef struct file_struct      file_type;
  129.  
  130. struct file_struct {
  131.  
  132.     char   *name_ptr;    /* Zero terminated name of file */
  133.  
  134.     char   *text_ptr;    /* Zero terminated text describing file */
  135.  
  136.     char   *lw_ptr;        /* Zero terminated last written date */
  137.  
  138.     FILE *  seq_fd;        /* fd to use for sequential access */
  139.  
  140.     FILE *  rnd_fd;        /* fd to use for random access */
  141.  
  142.     int     record_array_size;/* number of lines in the file (including
  143.                      DUMMY_RECORD_COUNT). */
  144.  
  145.     int    record_array_alloc;/* number of allocated entries in the
  146.                    record array. */
  147.  
  148. #define RA_ORIG    5000        /* Original # of records in record array */
  149. #define RA_INCR 5000        /* Number of records to add on each increment */
  150.  
  151.     record_type * record;    /* Allocated array of record descriptions.
  152.                    This field contains 0 if the file does not
  153.                    exists. (i.e., this is the third file in a
  154.                    two file comparison ) */
  155.  
  156. /*
  157.  * The entry below is actually the portion of the symbol table which
  158.  * needs an entry for each file. The array is indexed by 'hash_code'.
  159.  *
  160.  * Each index below is an index into the array for the specified file.
  161.  * Valid values are:
  162.  *
  163.  * 0:                      This line is not in this file.
  164.  * negative:               This line is not unique in the file.
  165.  *                         Value is negative index to one of the records.
  166.  * not negative:           This line occurs precisely once in the file.
  167.  *                         Value is index to the record.
  168.  */
  169.  
  170.     int    *sym_tab_index;    /* Index into 'record'. */
  171.                 /* There are 'sym_tab_size' elements in this array. */
  172. };
  173.  
  174. #define OLD_FILE   0        /* Array index of 'old' file */
  175. #define NEW1_FILE  1        /* Array index of 'new1' file */
  176. #define NEW2_FILE  2        /* Array index of 'new2' file */
  177. #define MAX_FILE_COUNT 3    /* Maximum number of files */
  178.  
  179. EXTERN int      file_count;    /* actual number of files */
  180.  
  181. EXTERN file_type files[MAX_FILE_COUNT];/* Description of the each file. */
  182.  
  183. /*
  184.  * For each record, six different relationships exist. That is,
  185.  * for each of the three files there is a relationship to each of the
  186.  * other two files.
  187.  * The tables below describe the six relationships.
  188.  */
  189.  
  190. #define MATCH_COUNT ( 2*MAX_FILE_COUNT )
  191.  
  192. EXTERN int      curr_file[MATCH_COUNT]
  193. #ifdef ALLOC
  194. = {
  195.     OLD_FILE, OLD_FILE, NEW1_FILE, NEW1_FILE, NEW2_FILE, NEW2_FILE
  196. }
  197. #endif
  198.            ;
  199.  
  200. /*Array of subsrcipts into the 'files' array of files which have
  201. relationships */
  202.  
  203. EXTERN int      corres_file[MATCH_COUNT]
  204. #ifdef ALLOC
  205. = {
  206.     NEW1_FILE, NEW2_FILE, OLD_FILE, NEW2_FILE, OLD_FILE, NEW1_FILE
  207. }
  208. #endif
  209.            ;
  210. /* Array of subscripts into the 'files' array of the file which is related to */
  211.  
  212.  
  213. EXTERN int      other_file[MATCH_COUNT]
  214. #ifdef ALLOC
  215. = {
  216.     NEW2_FILE, NEW1_FILE, NEW2_FILE, OLD_FILE, NEW1_FILE, OLD_FILE
  217. }
  218. #endif
  219.            ;
  220.  /* Array of subscripts into the 'files' array of the file which is not
  221.     involved in the current relationship */
  222.  
  223. EXTERN int      value_sub[MATCH_COUNT]
  224. #ifdef ALLOC
  225. = {
  226.     OLD_TO_NEW1, OLD_TO_NEW2, NEW1_TO_OLD, NEW1_TO_NEW2,
  227.     NEW2_TO_OLD, NEW2_TO_NEW1
  228. }
  229. #endif
  230.            ;
  231.  /* Array of subscripts to the 'value' array. This subscript identifies which
  232.     of the two relationships are being tested. */
  233.  
  234. EXTERN int      rev_value_sub[MATCH_COUNT]
  235. #ifdef ALLOC
  236. = {
  237.     NEW1_TO_OLD, NEW2_TO_OLD, OLD_TO_NEW1, NEW2_TO_NEW1,
  238.     OLD_TO_NEW2, NEW1_TO_NEW2
  239. }
  240. #endif
  241.            ;
  242.  /* Array of subscripts to the 'value' array. This subscript identifies the
  243.     relationship between the 'corres' file and the 'curr' file */
  244.  
  245. EXTERN int      other_value_sub[MATCH_COUNT]
  246. #ifdef ALLOC
  247. = {
  248.     NEW2_TO_OLD, NEW1_TO_OLD, NEW2_TO_NEW1, OLD_TO_NEW1,
  249.     NEW1_TO_NEW2, OLD_TO_NEW2
  250. }
  251. #endif
  252.            ;
  253.  /* Array of subscripts to the 'value' array. This subscript identifies the
  254.     relationship between the 'other' file and the 'curr' file */
  255.  
  256.  
  257. #define UNIQUE_MATCH_COUNT (MATCH_COUNT / 2)
  258.  
  259. EXTERN int      unique_match[UNIQUE_MATCH_COUNT]
  260. #ifdef ALLOC
  261. = {
  262.     0, 1, 3
  263. }
  264. #endif
  265.            ;
  266.  /* Array of subscripts into the relation arrays defined above. These are the
  267.     subscripts of the relations pairing each pair of files precisely once. */
  268. /*
  269.  * is_hash_code:
  270.  *
  271.  * This macro determines if the value in the record array is a hash code
  272.  * or an index into another file array. This macro relies on the fact
  273.  * that all hash codes are nagetive.
  274.  *
  275.  * Return value:
  276.  *      TRUE:  The value represents a hash code
  277.  *      FALSE: The value represents an index into a file array.
  278.  *
  279.  * Parameter:
  280.  *      value: The value from the file array.
  281.  */
  282.  
  283. #define is_hash_code( _value )  ((_value) < 0)
  284. /*
  285.  * Options:
  286.  */
  287.  
  288. EXTERN bool blank_compress INIT (FALSE);
  289.                 /* TRUE if blank compression is desired */
  290.  
  291. EXTERN bool blank_remove INIT (FALSE);/* TRUE if blank removal is desired */
  292.  
  293. EXTERN bool compress_records INIT (FALSE);
  294.                 /* TRUE if any record compression needs to
  295.                    occur */
  296.  
  297. EXTERN int      prefix_lines INIT (5);/* Number of prefix lines */
  298.  
  299. EXTERN int      postfix_lines INIT (5);/* Number of postfix lines */
  300.  
  301. EXTERN int      page_length INIT (PAGE_LENGTH);/* Number of lines/page */
  302.  
  303. EXTERN bool quiet_option INIT (FALSE);
  304.                 /* TRUE if COMBINE is to be quiet if there are
  305.                    no differences */
  306.  
  307. EXTERN bool pa_debug INIT (FALSE);/* TRUE for generic debugging */
  308. EXTERN bool p1_debug INIT (FALSE);/* TRUE for debug of pass 1 */
  309. EXTERN bool p2_debug INIT (FALSE);/* TRUE for debug of pass 2 */
  310. EXTERN bool p3_debug INIT (FALSE);/* TRUE for debug of pass 3 */
  311. EXTERN bool p4_debug INIT (FALSE);/* TRUE for debug of pass 4 */
  312. EXTERN bool p5_debug INIT (FALSE);/* TRUE for debug of pass 5 */
  313.  
  314. EXTERN bool statistics_flag INIT (FALSE);/* TRUE to output statistics */
  315.  
  316. EXTERN bool hed_flag INIT (FALSE);/* TRUE to output hed file */
  317.  
  318. EXTERN char     exec_time[LINE_LENGTH];/* Begin execution time */
  319.  
  320. /*
  321.  * Column specifications:
  322.  */
  323.  
  324. #define MAX_COLUMNS 32        /* maximum number of column ranges */
  325.  
  326. EXTERN int      column_count INIT (0);/* Actual number of column ranges */
  327.  
  328. EXTERN int      first_column[MAX_COLUMNS];/* first column to compare */
  329.                 /* Column numbers are 0 relative */
  330.  
  331. EXTERN int      last_column[MAX_COLUMNS];/* last column to compare */
  332.                  /* Column numbers are 0 relative */
  333.  
  334. /*
  335.  * other_sub:
  336.  *
  337.  * This macro is given the subscript to one of the elements in the
  338.  * 'value' array and returns the subscript to the other element.
  339.  * This macro is heavily dependent on the fact that there are only
  340.  * two elements in the value array.
  341.  *
  342.  * Return value:
  343.  *      other subscript
  344.  *
  345.  * Parameter:
  346.  *      value_sub: Subsrcipt into the value array.
  347.  */
  348.  
  349. #define other_sub( _sub )  ( 1 - (_sub) )
  350.  
  351. /*
  352.  * Primes: list of prime numbers.
  353.  *
  354.  * This array defines a set of prime numbers. For all multiples of 1024,
  355.  * this table contains the prime number which is less than but closest
  356.  * to that number.
  357.  *
  358.  * The list is terminated by a -1.
  359.  */
  360.  
  361. EXTERN int      primes[]
  362. #ifdef ALLOC
  363. = {
  364.     1021, 2039, 3067, 4093, 5119, 6143, 7159, 8191, 9209,
  365.     10223, 11261, 12281, 13309, 14327, 15359, 16381, 17401, 18427,
  366.     19447, 20479, 21503, 22511, 23549, 24571, 25589, 26597, 27647,
  367.     28669, 29683, 30713, 31741, 32749, 33791, 34807, 35839, 36857,
  368.     37879, 38903, 39929, 40949, 41983, 43003, 44029, 45053, 46073,
  369.     47093, 48121, 49139, 50159, 51199, 52223, 53239, 54269, 55291,
  370.     56311, 57331, 58367, 59387, 60413, 61417, 62459, 63487, 64499,
  371.     65521, 66553, 67579, 68597, 69623, 70639, 71671, 72701, 73727,
  372.     74747, 75773, 76781, 77813, 78839, 79867, 80863, 81919, 82939,
  373.     83939, 84991, 86011, 87037, 88037, 89087, 90107, 91129, 92153,
  374.     93179, 94207, 95231, 96233, 97259, 98299, 99317, 100343, 101363,
  375.     102397, 103423, 104417, 105467, 106487, 107509, 108541, 109567,
  376.     110587, 111611, 112621, 113657, 114679, 115693, 116731, 117757,
  377.     118757, 119797, 120829, 121853, 122869, 123887, 124919, 125941,
  378.     126967, 127997, 129023, 130043, 131071, 132071, 133117, 134129,
  379.     135151, 136189, 137209, 138239, 139241, 140281, 141311, 142327,
  380.     143357, 144383, 145399, 146423, 147451, 148471, 149503, 150523,
  381.     151549, 152567, 153589, 154621, 155627, 156671, 157679, 158699,
  382.     159739, 160757, 161783, 162791, 163819, 164839, 165887, 166909,
  383.     167917, 168943, 169957, 171007, 172031, 173053, 174079, 175103,
  384.     176123, 177131, 178169, 179173, 180221, 181243, 182261, 183289,
  385.     184309, 185327, 186343, 187387, 188407, 189439, 190409, 191473,
  386.     192499, 193513, 194543, 195581, 196597, 197621, 198647, 199679,
  387.     200699, 201709, 202751, 203773, 204797, 205823, 206827, 207869,
  388.     208891, 209917, 210943, 211949, 212987, 214009, 214993, 216061,
  389.     217081, 218111, 219133, 220151, 221173, 222199, 223229, 224251,
  390.     224737,
  391.     -1
  392. }
  393. #endif
  394.            ;
  395.  
  396. /*
  397.  * relate_type:
  398.  *
  399.  * This structure describes the relationsip between between a particular
  400.  * record of a particular file and corresponding records in the other
  401.  * files.
  402.  *
  403.  * This structure is built by 'pass5_analyze_relationship'. This structure
  404.  * is used by all of the other pass5 routines to determine whether the
  405.  * current record is the next one to be output.
  406.  */
  407.  
  408. struct relate_struct;
  409. typedef struct relate_struct    relate_type;
  410.  
  411. struct relate_struct {
  412.  
  413.     int     index[MAX_FILE_COUNT];
  414.                 /* Index that this record appears at in the
  415.                    file. Value will be a hash code if this
  416.                    record is not in the corresponding file */
  417.  
  418.     bool current[MAX_FILE_COUNT];
  419.                 /* TRUE if the record at the current position
  420.                    in the corresponding file */
  421.  
  422.     int     relation;    /* A summary of the relationship of this record
  423.                    to the current record in each file */
  424.     /* The zeroeth element is represented in the least significant bit,
  425.        etc. */
  426.  
  427. #define INSERT_NONE           0
  428. #define INSERT_OLD            1
  429. #define INSERT_NEW1           2
  430. #define INSERT_OLD_NEW1       (INSERT_OLD + INSERT_NEW1)
  431. #define INSERT_NEW2           4
  432. #define INSERT_OLD_NEW2       (INSERT_OLD + INSERT_NEW2)
  433. #define INSERT_NEW1_NEW2      (INSERT_NEW1 + INSERT_NEW2)
  434. #define INSERT_OLD_NEW1_NEW2  (INSERT_OLD + INSERT_NEW1 + INSERT_NEW2)
  435. #define INSERT_EOT            -1
  436.  
  437.     bool moved;        /* TRUE if this record is involved in a record
  438.                    movement. */
  439.  
  440.     bool in_all;        /* TRUE if the record is at the current
  441.                    position in all of the files. */
  442.  
  443. };
  444.  
  445. /*
  446.  * Statistics:
  447.  */
  448.  
  449. EXTERN int      cache_miss;    /* total number of cache misses. */
  450.  
  451. EXTERN int      hash_collisions;/* total number of hash collsions */
  452.  
  453. EXTERN int      old_new1_change_count;
  454.                 /* Number of differences between old and new1
  455.                    files */
  456.  
  457. EXTERN int      old_new2_change_count;
  458.                 /* Number of differences between old and new2
  459.                    files */
  460.  
  461. EXTERN int      new1_new2_change_count;
  462.                 /* Number of differences between new1 and new2
  463.                    files */
  464.  
  465. /*
  466.  * Symbol Table:
  467.  *
  468.  * This structure describes a the symbol table.
  469.  * Each entry in the symbol table represents a record in one of the files.
  470.  * The contents of each record is hashed.
  471.  * The hash value is used as an index into the arrays.
  472.  * If the hash value is not unique, a re-hash is performed until a
  473.  * unique hash value is obtained.
  474.  *
  475.  * The symbol table is organized as four arrays of entries.
  476.  * There is one array for each file and one array of cache entry pointers
  477.  * described below.
  478.  */
  479.  
  480. /*
  481.  * The index into the symbol table is a hash code. Hash codes are positive.
  482.  * Significant hash codes include:
  483.  *
  484.  * 0: Not valid
  485.  * 1: begin record
  486.  * 2: end record
  487.  * 3: eof (some archaic operating systems allow multiple eof's in a file.)
  488.  */
  489.  
  490. #define HASH_FREE_ENTRY 0    /* A hash code of this value indicates a free
  491.                    entry. This value is used in a cache entry
  492.                    to indicate an unused cache entry */
  493.  
  494. /*
  495.  * The cache ptr below is a pointer to the cache entry for the line.
  496.  * Valid values are:
  497.  *
  498.  * CACHE_FREE_ENTRY:       This symbol table entry is unused.
  499.  * CACHE_NOT_IN_CACHE:     This line is no longer in the cache.
  500.  * positive:               Pointer to cache entry.
  501.  */
  502.  
  503. EXTERN cache_entry_type * *sym_tab_cache_ptr;
  504.                 /* Pointer to table of pointers to cache
  505.                    entries */
  506.  
  507. #define CACHE_FREE_ENTRY 0    /* Symbol table entry is unused */
  508.  /* The code depends on the fact that the allocator zeros this entry upon
  509.     allocation */
  510.  
  511. #define CACHE_NOT_IN_CACHE -1    /* This line no longer in cache */
  512.  
  513. EXTERN int      sym_tab_size;    /* Number of entries in the symbol table. */
  514. /*
  515.  * Procedure forwards:
  516.  */
  517.  
  518. void dump_arrays() ;
  519. void dump_statistics() ;
  520. void dump_sym_tab() ;
  521.  
  522. void error() ;
  523. char * mem_alloc() ;
  524. void init() ;
  525. void link_records() ;
  526.  
  527. void pass1() ;
  528. int  pass1_read_record() ;
  529. void pass1_record_compress() ;
  530.  
  531. void pass2() ;
  532.  
  533. void pass3() ;
  534. void pass3_scan() ;
  535.  
  536. void pass4() ;
  537. void pass4_scan() ;
  538.  
  539. void pass5() ;
  540. void pass5_analyze_relationship() ;
  541. int  pass5_move() ;
  542. void pass5_dump_record() ;
  543. void pass5_write_hed() ;
  544. void pass5_write_listing() ;
  545. void pass5_write_listing_line() ;
  546. void pass5_write_listing_head() ;
  547.